// 找出两个字符串中所有唯一的公共字母
class Set {
    constructor () {
      this.items = {}
    }
    has (element) {
      return element in this.items
    }
    add (element) {
      if (!this.has(element)) {
        this.items[element] = element
        return true
      }
      return false
    }
    delete (element) {
      if (this.has(element)) {
        delete this.items[element]
        return true
      }
      return false
    }
    clear () {
      this.items = {}
    }
    size () {
      return Object.keys(this.items).length
    }
    values () {
      return Object.values(this.items)
    }
}

// function findDuplicates(nums) {
//     const seen = new Set();
//     const duplicates = new Set();

//     for (const num of nums) {
//         if (seen.has(num)) {
//             duplicates.add(num);
//         } else {
//             seen.add(num);
//         }
//     }

//     return Array.from(duplicates);
// }

// // 示例使用
// const arr1 = [1, 2, 3, 2, 4, 3, 5];
// console.log(findDuplicates(arr1)); // 输出: [2, 3]

// const arr2 = [1, 1, 1, 2, 2, 3];
// console.log(findDuplicates(arr2)); // 输出: [1, 2]


function isAnagram(s, t) {
    if (s.length !== t.length) return false;

    const sSet = new Set(s.split(''));
    const tSet = new Set(t.split(''));

    if (sSet.size !== tSet.size) return false;

    for (const char of sSet) {
        if (!tSet.has(char)) return false;
    }

    return true;
}

// 示例使用
console.log(isAnagram("anagram", "nagaram")); // 输出: true
console.log(isAnagram("rat", "car"));         // 输出: false
console.log(isAnagram("listen", "silent"));   // 输出: true